cmake_minimum_required(VERSION 3.16)
project(my_zc4 LANGUAGES CXX)

if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
  add_compile_options(-Wall -Wextra)
endif()

# set the same behavior for windows as it is on linux
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

# find dependencies
set(THIS_PACKAGE_INCLUDE_DEPENDS
  hardware_interface
  pluginlib
  rclcpp
  rclcpp_lifecycle
)

# find dependencies
find_package(backward_ros REQUIRED)
find_package(ament_cmake REQUIRED)
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
  find_package(${Dependency} REQUIRED)
endforeach()

include_directories(${PROJECT_SOURCE_DIR}/hardware/include)

## COMPILE
add_library(
  my_zc4  SHARED
  hardware/zc4.cpp
)
target_compile_features(my_zc4 PUBLIC cxx_std_17)
target_include_directories(my_zc4 PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/hardware/include/ros2_control_demo_example_9>
$<INSTALL_INTERFACE:include/my_zc4>
)
ament_target_dependencies(
  my_zc4 PUBLIC
  ${THIS_PACKAGE_INCLUDE_DEPENDS}
)

# Export hardware plugins
pluginlib_export_plugin_description_file(hardware_interface my_zc4.xml)

# 添加teleop_keyboard_node可执行文件
add_executable(teleop_keyboard_node_cpp
  hardware/teleop_keyboard_node.cpp
)
ament_target_dependencies(teleop_keyboard_node_cpp
  rclcpp
  std_msgs
)

# INSTALL
install(
  DIRECTORY hardware/include/
  DESTINATION include/my_zc4)
install(
  DIRECTORY description/launch description/ros2_control description/urdf description/gazebo
  DESTINATION share/${PROJECT_NAME})
install(
  DIRECTORY bringup/launch bringup/config
  DESTINATION share/${PROJECT_NAME}/bringup)
install(TARGETS my_zc4  EXPORT export_my_zc4  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)
install(
  FILES description/urdf/zc4_description.urdf.xacro
  DESTINATION share/${PROJECT_NAME}/description/urdf
)
install(
  FILES description/urdf/zc4.materials.xacro
  DESTINATION share/${PROJECT_NAME}/description/urdf
)
install(
  FILES description/ros2_control/zc4.ros2_control.xacro
  DESTINATION share/${PROJECT_NAME}/description/ros2_control
)
install(TARGETS
  teleop_keyboard_node_cpp
  DESTINATION lib/${PROJECT_NAME}
)
if(BUILD_TESTING)
  find_package(ament_cmake_pytest REQUIRED)

  ament_add_pytest_test(zc4_urdf_xacro test/test_urdf_xacro.py)
  ament_add_pytest_test(view_zc4_launch test/test_view_robot_launch.py)
  # ament_add_pytest_test(run_zc4_launch test/test_zc4_launch.py)
endif()

## EXPORTS
ament_export_targets(export_my_zc4 HAS_LIBRARY_TARGET)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_package()
